import { relation_describe_db_info } from '../Classes/cla_relation_describe_db_info';
import { get_db_relation_describe } from './get_mdb';

/**
 * 填充 关系 词 正 反
 * @param inv 下行 描述词
 * @param rev 上行 描述词
 */
export async function add_relation_describe(inv: string, rev?: string) {
  let db_relation_describe = get_db_relation_describe();
  if (rev == undefined) {
    rev = inv;
  }

  let describe_info = new relation_describe_db_info(inv, rev);

  let check_inv_arr = await db_relation_describe.find({ inv: inv }).toArray();

  if (check_inv_arr.length > 0) {
    return;
  }

  let check_rev_arr = await db_relation_describe.find({ rev: inv }).toArray();

  if (check_rev_arr.length > 0) {
    return;
  }

  await db_relation_describe.insertOne(describe_info);
}
